package cn.itsource.service.impl;

import cn.itsource.domain.Employee;
import cn.itsource.repository.EmployeeRepository;
import cn.itsource.service.IEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(propagation = Propagation.SUPPORTS,readOnly = true)
public class EmployeeServiceImpl implements IEmployeeService {

    @Autowired
    private EmployeeRepository repository;
    @Transactional
    @Override
    public void add(Employee employee) {

        repository.save(employee);
    }

    @Transactional
    @Override
    public void del(Long id) {
        repository.deleteById(id);
    }

    @Transactional
    @Override
    public void update(Employee employee) {
        repository.save(employee);
    }

    @Override
    public Employee getById(Long id) {
        return repository.findById(id).get();
    }

    @Override
    public List<Employee> getAll() {
        return repository.findAll();
    }
}
